package com.itheima.demo;

import com.itheima.domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/17 16:54
 */
@SuppressWarnings("all")
public class Demo_008 {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //获取字节码对象 ;
        Class clazz = Person.class;

        //获取构造方法 ;
        Constructor constructor = clazz.getConstructor();

        //创建对象 ;
        Object person = constructor.newInstance();

        //获取成员方法;
        Method method = clazz.getMethod("method", String.class);

        //调用方法;
        Object invoke = method.invoke(person, "robin");

        //打印;
        System.out.println(invoke);
    }
}
